<?php include_once('header.php'); ?>

<?php include_once('left_navigation.php'); ?>

<?php
include('../classess/add_bankdetail.php');
$bankdetail = new add_bankdetail();

$affiliate_id = $_SESSION['id'];
$add_bankdetail = '';
if(isset($_POST['payment_method']) && $_POST['payment_method'] != ''){
    $add_bankdetail = $bankdetail->bankdetail_add($affiliate_id);
    
}
$banks_details = $bankdetail->get_details($affiliate_id);

?>



<div class="col-lg-12"><!-- Start Middle Content Div-->

    <div class="box">

		<div class="col-lg-12" style="margin-top:-20px; text-align:center;">
			<div class="box" style="font-size:16px;">
				Your Refrence URL is 
				<a href="<?php echo ReferenceLink; ?>" target="_blank" style="text-decoration:none; color:blue; "><?php echo ReferenceLink; ?></a>	
			</div>
		</div>

        <div class="box-header" data-original-title=""><!-- Start Box Header Div-->

            <h2><i class="fa fa-edit"></i><span class="break"></span>Bank Detail</h2>

            <div class="box-icon">

                <a href="gallery.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>

                <a href="gallery.html#" class="btn-close"><i class="fa fa-times"></i></a>

            </div>

        </div><!-- End Box Header Div-->

        
        <div class="box-content"><!-- Start Box Content Div-->

            <div class="row">

                <div class="col-sm-12">
                    <?php if($add_bankdetail){?>
<div class="alert alert-info">

                            <div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>

                            <div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $add_bankdetail;?></div>

                            <div style="clear:both;"></div>							

                        </div>
                    <?php }?>

                    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?aff_bank=1" name="add_aff_bank_detail" id="add_aff_bank_detail" enctype="multipart/form-data">

                        <div class="main_form_box col-sm-6">

                            <div class="form-content  form-content-form">								



                                <label>Payment Method</label>

                                <select id="payment_method" name="payment_method">
                                    <option value="bank" <?php if (isset($banks_details['0']->b_payment_type)) {
        if ($banks_details['0']->b_payment_type == 'bank') echo 'selected="selected"';
    } ?> >Bank</option>
                                    <option value="paypal" <?php if (isset($banks_details['0']->b_payment_type)) {
        if ($banks_details['0']->b_payment_type == 'paypal') echo 'selected="selected"';
    } ?>>Paypal</option>
                                </select>

                                <span class="bank_details" <?php if (isset($banks_details['0']->b_payment_type)) {
                                if ($banks_details['0']->b_payment_type == 'paypal'): echo "style='display:none'"; endif;}?>>
                                <label>Bank Name</label>

                                <input type="text" name="b_bank_name" id="b_bank_name" value="<?php if (isset($banks_details[0]->b_bank_name)) {
    echo $banks_details[0]->b_bank_name;} ?>" > 



                                <label>Account Number</label>

                                <input type="text" name="b_bank_acc_no" id="b_bank_acc_no" value="<?php if (isset($banks_details['0']->b_bank_acc_no)) {
    echo $banks_details['0']->b_bank_acc_no;} ?>" >
	
	
	 <label>PanCard</label>

                                <input type="text" name="b_pancard" id="b_pancard" value="<?php if (isset($banks_details['0']->b_pancard)) {
    echo $banks_details['0']->b_pancard;} ?>" >

                            </div>

                        </div>



                        <div class="main_form_box col-sm-6" >

                            <div class="form-content  form-content-form">

<span class="bank_details" <?php if (isset($banks_details['0']->b_payment_type)) {
                                if ($banks_details['0']->b_payment_type == 'paypal'): echo "style='display:none'"; endif;}?>>

                                <label>Branch</label>

                                <input type="text" name="b_bank_branch" id="b_bank_branch" value="<?php if (isset($banks_details['0']->b_bank_branch)) {
    echo $banks_details['0']->b_bank_branch;} ?>" >

                                <label>Swipe Code</label>

                                <input type="text" name="b_bank_swipe_code" id="b_bank_swipe_code" value="<?php if (isset($banks_details['0']->b_bank_swipe_code)) {
    echo $banks_details['0']->b_bank_swipe_code;} ?>"> 

                                </span>
                                <span id="paypal_details" <?php if (isset($banks_details['0']->b_payment_type)) {
                                if ($banks_details['0']->b_payment_type == 'bank'): echo "style='display:none'"; endif;}else {echo "style='display:none'";}?>>
                                <label>Paypal Name</label>
                                <input type="text" name="b_paypal_name" id="b_paypal_name" value="<?php if (isset($banks_details['0']->b_paypal_name)) {
    echo $banks_details['0']->b_paypal_name;} ?>"> 
                                </span>

<label>Address</label>
                                <input type="text" name="b_address" id="b_address" value="<?php if (isset($banks_details['0']->b_address)) {
    echo $banks_details['0']->b_address;} ?>"> 

                                <label style="text-align:right; margin-top:35px;">

                                    <button type="button" class="btn btn-blue login_button" name="add_bank_detail" id="add_bank_detail">
                                        
        
                                        <?php 
                                        if(isset($banks_details['0']->b_payment_type)){
                                            echo 'Edit';
                                        }else{
                                            echo 'Add';
                                        }
?></button> 							

                                </label>

                            </div>

                        </div>

                        <div style="clear:both;"></div>

                        

                    </form>



                </div><!--/col-->

            </div><!-- End Row div -->

        </div><!-- End Box Content Div -->



    </div><!-- End Box Div-->

</div><!-- End Middle Content Div-->

<?php include_once('footer.php'); ?>

<script>

	$ = jQuery.noConflict();

	$(document).ready(function(){
            
            $("#payment_method").change(function(){
               if($(this).val() == 'bank' ){
                   $("#paypal_details").hide();
                   $(".bank_details").show();
               } else{
                   $("#paypal_details").show();
                   $(".bank_details").hide();
               }
            });
            
            
            $("#add_bank_detail").click(function(){
               var payment_type = $("#payment_method").val();
               var bank_name = $("#b_bank_name").val();
               var bank_acc_no = $("#b_bank_acc_no").val();
               var bank_branch = $("#b_bank_branch").val();
               var bank_swipe_code = $("#b_bank_swipe_code").val();
               var paypal_name = $("#b_paypal_name").val();
               var regex = /(\d.*){10}/;
               if(payment_type == ''){
                   alert('Please select payment type');
                   $('#course_name').focus();
                   return (false);
               }else if(bank_name == '' && payment_type == 'bank'){
                   alert('Please enter bank name');
                   $('#b_bank_name').focus();
                   return (false);
               } else if(bank_acc_no == '' && payment_type == 'bank'){
                   alert('Please enter account no');
                   $('#b_bank_acc_no').focus();
                   return (false);
               } else if(bank_acc_no != '' && regex.test(bank_acc_no) == false  && payment_type == 'bank'){
                   alert('Please enter valid account no');
                   $('#b_bank_acc_no').focus();
                   return (false);
               } else if(bank_branch == '' && payment_type == 'bank'){
                   alert('Please enter branch');
                   $('#b_bank_branch').focus();
                   return (false);
               } else if(bank_swipe_code == '' && payment_type == 'bank'){
                   alert('Please enter swipe code');
                   $('#b_bank_swipe_code').focus();
                   return (false);
               } else if(paypal_name == '' && payment_type == 'paypal'){
                   alert('Please select payment type');
                   $('#b_paypal_name').focus();
                   return (false);
               } else{
                   $("#add_aff_bank_detail").submit();
               }
               
            });
            
        });
</script>